package com.sywl.ytcx.controller.front;

import com.sywl.ytcx.entity.res.ResponseResult;
import com.sywl.ytcx.util.JwtUtil;
import com.sywl.ytcx.util.VerTokenUtil;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/api/test")
public class TestController  {
    @RequestMapping("/test")
    public ResponseResult test() {
        return new ResponseResult("S200", "测试成功", null);
    }

    /**
     * 解析请求头token示例
     * @header authorization //这里决定用小写开头
     * @return 解析结果
     *
     * 解析失败返回E400
     * 解析成功返回S200
     */
    @PostMapping("/vertoken")
    public ResponseResult test2(@RequestHeader("authorization") String authorization) {
        int userId = VerTokenUtil.getUserId(authorization);
        if (userId == -1) {
            return new ResponseResult("E400", "KEY-TOKEN错误", null);
        }
        return new ResponseResult("S200", "解析成功,user存在",  VerTokenUtil.getUserId(authorization));
    }
}
